<template>
  <div class="login">
    <div class="login-container">
      <div class="login-wrapper">
        <span class="title">{{ currenType }}登录</span>
        <div class="type-btn-wrap">
            <button
                v-for="(item,index) in type"
                :key="index"
                class="no-btn"
                @click="changeType(index)"
                :class="{btn_active:index === loginType}"
            >{{item}}</button>
        </div>
        <component :is="currenComponent" ref="loginRef"/>
        <div class="from-btn-container" v-show="loginType !== 1">
            <div class="form-btn-wrap">
                <div class="btn-bg"></div>
                <button class="form-btn pointer" @click="doLogin">
                     {{btnText}} <i class="el-icon-loading" v-show="isLoading"></i>
                </button>
            </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import LoginByPhone from "@/components/login/LoginByPhone.vue"
import LoginByQr from "@/components/login/LoginByQr.vue"
import LoginByCode from "@/components/login/LoginByCode.vue"
export default {
  components:{LoginByPhone,LoginByQr,LoginByCode},
  data() {
    return {
      isLoading: false,
      loginType: 2, //,
      loginComponent: ['LoginByPhone', 'LoginByQr', 'LoginByCode'],
      type: ['手机号', '二维码', '验证码'],
    };
  },
  computed:{
    currenType() {
      return this.type[this.loginType];
    },
    currenComponent(){
        return this.loginComponent[this.loginType];
    },
    btnText(){
        return this.isLoading ? '登录中' : '登录';
    }
  },
  methods:{
    changeType(index){
        this.loginType = index;
    },
    doLogin(){
        // 手机号码登录
        if(this.loginType === 0 || this.loginType === 2){
          this.$refs.loginRef.doLogin();
        }
    }
  },
  //登录完成
  beforeDestroy(){
    this.$store.dispatch('getAcount');
  }
};
</script>

<style lang="less" scoped>
.login{
    width: 100%;
    margin: 0 auto;
    overflow: hidden;
    .login-container{
        min-height: 100vh;
        background-image: url(@/assets/img/login.jpg);
        background-size: 100% 100%;
        background-repeat: no-repeat;
        display: flex;
        justify-content: center;
        align-items: center;
    }
}
.login-wrapper{
  width: 500px;
  height: 600px;
  background-color: #ffffff;
  border-radius: 10px;
  padding: 65px 55px 54px 55px;
  .title {
    display: block;
    font-size: 30px;
    color: #423d3d;
    line-height: 1.2;
    text-align: center;
    padding-bottom: 49px;
  }
  .type-btn-wrap{
    display: flex;
    justify-content: center;
    .no-btn{
        font-size: 16px;
    }
    .btn_active{
        font-weight: bold;
        &::after{
            content: '';
            display: block;
            width: 100%;
            height: 2px;
            background-color: #000;
        }
    }
  }
}
.from-btn-container{
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 50px;
    cursor: pointer !important;
    .form-btn-wrap {
    width: 100%;
    display: block;
    position: relative;
    z-index: 1;
    border-radius: 25px;
    overflow: hidden;
    margin: 0 auto;
    &:hover .btn-bg {
      background-position-x: 200px;
    }
    .btn-bg {
      position: absolute;
      z-index: -1;
      width: 300%;
      height: 100%;
      background: #a64bf4;
      background: -webkit-linear-gradient(
        right,
        #00dbde,
        #fc00ff,
        #00dbde,
        #fc00ff
      );

      top: 0;
      left: -100%;
      transition: all 0.5s;
    }
    .form-btn {
      font-size: 16px;
      color: #fff;
      line-height: 1.2;
      text-transform: uppercase;
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 0 20px;
      width: 100%;
      height: 50px;
      outline: none;
      border: none;
      background: transparent;
      i{
        margin-right: 3px;
      }
    }
  }
}
</style>